﻿using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCCommon.Enums;
using BCDto.Common.NotificationMessageRecord;
using BCService.Common.NotificationMessageRecord;
using BCTMSRESTful.Configs;

namespace BCTMSRESTful.Controllers.Management.NotificationMessage
{
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class NotificationMessageRecordController : ManagementBaseController
    {
        private readonly INotificationMessageRecordService notificationMessageRecordService;

        public NotificationMessageRecordController(INotificationMessageRecordService notificationMessageRecordService)
        {
            this.notificationMessageRecordService = notificationMessageRecordService;
        }

        #region 获取通知消息未读总数
        /// <summary>
        /// 获取通知消息未读总数
        /// </summary>
        /// <response code="200">通知消息未读总数</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(int), 200)]
        public IActionResult NoneReadCount()
        {
            var unreadCount = this.notificationMessageRecordService.GetUnreadCount(this.Admin, null);

            return this.Ok(unreadCount);
        }
        #endregion

        #region 获取通知消息记录(分页)
        /// <summary>
        /// 获取通知消息记录(分页)
        /// </summary>
        /// <param name="isRead">是否已读</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">订单信息</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<NotificationMessageRecordDto>), 200)]
        public IActionResult Get([FromQuery(Name = "is_read")] bool? isRead,
            int pageIndex = 1,
            int pageSize = 10)
        {
            var pageableList = this.notificationMessageRecordService.GetPageableList(this.Admin, null, isRead, null, pageIndex, pageSize);

            return this.Ok(pageableList);
        }

        #endregion

        #region 修改通知消息为已读
        /// <summary>
        /// 修改通知消息为已读
        /// </summary>
        /// <param name="notificationMessageId">通知消息Id</param>
        /// <response code="200">订单信息</response>
        /// <returns></returns>
        [HttpPut("{notification_message_id}")]
        [Log("修改通知消息为已读")]
        [ProducesResponseType(typeof(PageableList<NotificationMessageRecordDto>), 200)]
        public IActionResult Put([FromRoute(Name = "notification_message_id")] long notificationMessageId)
        {
            return Ok(this.notificationMessageRecordService.UpdateReadStatus(notificationMessageId));
        }
        #endregion

        #region  根据类型分组未读获取消息行数
        /// <summary>
        /// 根据类型分组未读获取消息行数
        /// </summary>
        /// <response code="200">根据类型分组未读获取消息行数</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<NotificationGroupMessageCountDto>), 200)]
        public IActionResult GetMessageCount()
        {
            var list = this.notificationMessageRecordService.GetGroupUnreadCount(this.Admin, null);

            return this.Ok(list);
        }

        #endregion

        #region 根据类别获取通知消息记录
        /// <summary>
        /// 获取通知消息记录
        /// </summary>
        /// <param name="notificationMessageRecordType">通知类型</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">订单信息</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<NotificationMessageRecordDto>), 200)]
        public IActionResult QueryNotificationType([FromQuery(Name = "notification_message_record_type")] NotificationMessageRecordType? notificationMessageRecordType,
            int pageIndex = 1,
            int pageSize = 10)
        {
            var pageableList = this.notificationMessageRecordService.GetPageableList(this.Admin, null, false, notificationMessageRecordType, pageIndex, pageSize);

            return Ok(pageableList);
        }
        #endregion

        #region 处理通知消息
        /// <summary>
        /// 处理通知消息
        /// </summary>
        /// <response code="200">处理通知消息成功</response>
        /// <returns></returns>
        [Log(" 处理通知消息")]
        [HttpPut("[action]/{notification_message_id}")]
        [ProducesResponseType(typeof(NotificationMessageRecordDto), 200)]
        public IActionResult HandledMessage([FromRoute(Name = "notification_message_id")] long notificationMessageId, [FromBody] NotificationMessageRecordHandledDto notificationMessageRecordHandledDto)
        {
            return Ok(this.notificationMessageRecordService.UpdateIsHandled(this.Admin, notificationMessageId, notificationMessageRecordHandledDto.HandledRemark));
        }
        #endregion

        #region 一键阅读
        /// <summary>
        /// 一键更改消息读取状态为已读
        /// </summary>
        /// <param name="notificationMessageRecordType">通知类型</param>
        /// <response code="200">修改通知消息为已读成功</response>
        /// <returns></returns>
        [Log(" 一键更改消息读取状态为已读")]
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(PageableList<NotificationMessageRecordDto>), 200)]
        public IActionResult UpdateBatchIsRead([FromQuery(Name = "notification_message_record_type")] NotificationMessageRecordType? notificationMessageRecordType)
        {
            return Ok(this.notificationMessageRecordService.UpdateBatchIsRead(this.Admin, notificationMessageRecordType));
        }
        #endregion
    }
}
